#!/bin/bash

# 设置JaCoCo代理路径和参数
JACOCO_AGENT_PATH="./jacocoagent.jar"
JACOCO_DEST_FILE="./target/jacoco-runtime.exec"
JACOCO_AGENT_OPTS="destfile=$JACOCO_DEST_FILE,includes=com.example.*,excludes=java.*:javax.*:sun.*:com.sun.*:org.hibernate.*:net.bytebuddy.*:*\$HibernateProxy*:*\$HibernateInstantiator*:*\$ByteBuddy*:*\$EnhancerBy*,append=true"

# 检查jacocoagent.jar是否存在
if [ ! -f "$JACOCO_AGENT_PATH" ]; then
    echo "错误: 未找到jacocoagent.jar文件"
    echo "文件应位于: $JACOCO_AGENT_PATH"
    echo "请确保项目根目录中有jacocoagent.jar文件"
    exit 1
fi

# 启动应用程序
echo "使用以下JaCoCo配置启动应用程序:"
echo "$JACOCO_AGENT_OPTS"

java -javaagent:"$JACOCO_AGENT_PATH"="$JACOCO_AGENT_OPTS" -jar ./target/demo-0.0.1-SNAPSHOT.jar

echo ""
echo "如果应用程序成功启动，可以通过浏览器访问 http://localhost:8080"
echo "JaCoCo覆盖率报告将保存到: $JACOCO_DEST_FILE"
echo ""